<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>

<script>
    (function () {
        function isWeiXin() {
            const query = new URLSearchParams(window.location.search);
            let token = query.get('token');
            let clientId = query.get('clientId');
            let equipmentId = query.get('equipmentId');
            let orderType = query.get('orderType');
            let baseUrl = query.get('baseUrl');
            let printQuantity = query.get('printQuantity');
            let printType = query.get('printType');
            let singleDouble = query.get('singleDouble');
            let ua = window.navigator.userAgent.toLowerCase();
            // 使用 test 方法检查是否包含 "micromessenger"
            if (/micromessenger/.test(ua)) {
                sendPost(1, token, clientId, equipmentId, orderType, baseUrl, printQuantity, printType, singleDouble);
                return "wechat"
            } else if (/alipayclient/.test(ua)) {
                sendPost(2, token, clientId, equipmentId, orderType, baseUrl, printQuantity, printType, singleDouble);
                return "alipay"
            } else {
                // sendPost(1);
                return "unknow"
            }
        }

        // 调用 fetch 方法，将 appType 发送到指定接口
        function sendPost(type, token, clientId, equipmentId, orderType, baseUrl, printQuantity, printType, singleDouble) {
            fetch(baseUrl + '/api/v1.0/print/addPrintOrder', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'fate-token': token
                },
                body: JSON.stringify({
                    clientId,
                    equipmentId,
                    orderType,
                    payType: type,
                    printQuantity,
                    printType,
                    singleDouble
                })
            })
                .then(response => response.json())
                .then(res => {
                    if (res.code === 200) {
                        console.log('请求成功:', res.data);
                        fetch(baseUrl + '/api/v1.0/provider/payment/fuyoupay/equipment/fuYouPaymentRequest?orderId=' + res.data.value, {
                            method: 'POST',
                            headers: {
                                'Content-Type': 'application/json',
                                'fate-token': token
                            }
                        }).then(response => response.json()).then(res => {
                            if (res.code === 200) {
                                // 跳转res.data.qrCode
                                window.location.href = res.data.qrCode
                            }
                        })
                    } else {
                        console.error('请求失败:', res.msg);
                    }
                })
                .catch(error => {
                    console.error('请求出错:', error);
                });
        }

        isWeiXin()
    })()
</script>
</body>
</html>